import { request, get } from '../ajax'
import { getAjaxBaseUrl } from '../handler'

const controller = getAjaxBaseUrl('/template', '/energy')

/** 根据模型编码查询模型树 */
export function getTemplateTree(modelCode: string) {
  return get<any>(`${controller}/${modelCode}`)
}

/** 导出 */
export function exportData(params: any) {
  return request({
    url: `${controller}/export`,
    method: 'post',
    data: params,
    responseType: 'blob',
  })
}

/** template_001 */
export function exportData1(params: any) {
  return post(`${controller}/monio-export`, params)
}

/** template_002 */
export function exportData2(params: any) {
  const data = {
    ...params,
    cycle: ({
      '1H': 1,
      '1d': 2,
      '1M': 3,
    } as any)[params.timeType],
  }
  delete data.timeType
  return post(`${controller}/monio-export2`, data)
}

/** 分页查询表格列表数据(template_001) */
export function getTableList(params: any) {
  return get(`${controller}/page`, params)
}

/** 分页查询表格列表数据(template_002) */
export function getTableList2(params: any) {
  const data = {
    ...params,
    cycle: ({
      '1H': 1,
      '1d': 2,
      '1M': 3,
    } as any)[params.timeType],
  }
  delete data.timeType
  return get(`${controller}/page2`, data)
}
